package com.example.kuaidichaxunapplication;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.kuaidichaxunapplication.jiekou.BaseData;
import com.example.kuaidichaxunapplication.jiekou.KdSearch;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class MainActivity extends AppCompatActivity {
    String code="9c3d72e78ae1418f8dc7e9d0511d0b9b";
    List<String> dataBak = new ArrayList<>();
    List<BaseData.Trace> data=new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ListView lv = findViewById(R.id.lv);
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("https://api09.aliyun.venuscn.com/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        KdSearch search = retrofit.create(KdSearch.class);
        Call<BaseData> kd = search.getKD("75422961880316", "");
        kd.enqueue(new Callback<BaseData>() {
            @Override
            public void onResponse(Call<BaseData> call, Response<BaseData> response) {
                Log.d("TAG", "onResponse: "+response.body().getData().getTraces().get(0).getDesc()+"-----success--->") ;
            }

            @Override
            public void onFailure(Call<BaseData> call, Throwable t) {
                Log.e("--failed-->", t.getMessage());
            }
        });
    }

    class MyAdapter extends BaseAdapter {
        @Override
        public int getCount() {
            return data.size();
        }

        @Override
        public Object getItem(int position) {
            return data.size();
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView==null){
                convertView=getLayoutInflater().inflate(R.layout.cell,null);
            }
            TextView msg=convertView.findViewById(R.id.msg);
            TextView date=convertView.findViewById(R.id.date);
            BaseData.Trace trace=data.get(position);
            msg.setText(trace.getDesc());
            date.setText(trace.getTime());
            return convertView;
        }
    }
}